package com.xy.springboot.game.task.start;

import com.iohao.game.action.skeleton.core.BarSkeleton;
import com.iohao.game.action.skeleton.core.BarSkeletonBuilder;
import com.iohao.game.action.skeleton.core.BarSkeletonBuilderParamConfig;
import com.iohao.game.action.skeleton.core.doc.BroadcastDocument;
import com.iohao.game.bolt.broker.client.AbstractBrokerClientStartup;
import com.iohao.game.bolt.broker.core.client.BrokerClient;
import com.iohao.game.bolt.broker.core.client.BrokerClientBuilder;
import com.xy.springboot.game.common.config.BarSkeletonConfig;
import com.xy.springboot.game.common.constant.cmd.TaskCmdModule;
import com.xy.springboot.game.common.data.TaskData;
import com.xy.springboot.game.task.action.LoginAction;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.FieldDefaults;

/**
 * 任务逻辑服，启动配置
 */
@Getter
@Setter
@FieldDefaults(level = AccessLevel.PRIVATE)
public class GameLogicTaskLogic extends AbstractBrokerClientStartup {

    @Override
    public BarSkeleton createBarSkeleton() {
        // 业务框架构建器 配置
        BarSkeletonBuilderParamConfig config = BarSkeletonConfig.createBarSkeletonBuilderParamConfig()
                // 扫描 action 类所在包
                .scanActionPackage(LoginAction.class);
        // 业务框架构建器
        BarSkeletonBuilder builder = BarSkeletonConfig.createBarSkeletonBuilder(config);
        extractedDoc(builder);
        // 开启 jsr380 验证
        builder.getSetting().setValidator(true);
        return builder.build();
    }
    private void extractedDoc(BarSkeletonBuilder builder) {
        // list value
        builder.addBroadcastDocument(BroadcastDocument.newBuilder(TaskCmdModule.of(TaskCmdModule.TASK_LIST))
                .setDataClassList(TaskData.class)
                .setMethodDescription("TaskDataList")
                .setMethodName("TaskList")
        );
    }
    @Override
    public BrokerClientBuilder createBrokerClientBuilder() {
        BrokerClientBuilder builder = BrokerClient.newBuilder();
        builder.appName("spring Task 逻辑服");
        return builder;
    }
}
